package com.common.controller;

import com.common.controller.BaseController;
import com.common.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @classDescription:
 * @author:xiayingjie
 * @createTime:16/8/13
 */
@RequestMapping(value = "redirect")
@Controller
public class RedirectController extends BaseController{

    //redirectAttributes 表示重定向
    @RequestMapping(value = "find")
    public String find(HttpServletRequest request, HttpServletResponse response,int id, RedirectAttributes model) throws Exception {
        User user=this.userService.findById(id);
        model.addAttribute("hello", "world");
        model.addFlashAttribute("user", user);
        return   "redirect:/redirect/show";

    }

    @RequestMapping(value = "show")
    @ResponseBody
    public JsonResult find(HttpServletRequest request, HttpServletResponse response,String hello, User user, Model model) throws Exception {
        System.out.println(hello);

        return new JsonResult(ResultCode.SUCCESS,user);
    }
}
